package com.ruantu.clothing.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruantu.clothing.dao.*;
import com.ruantu.clothing.entity.*;
import com.ruantu.clothing.entity.combobox.RukuTuiCombobox;
import com.ruantu.clothing.entity.finance.FinanceRecord;
import com.ruantu.clothing.service.RukuService;
import com.ruantu.clothing.service.finance.FinanceService;
import com.ruantu.clothing.util.MyException;
import com.ruantu.clothing.util.UUIDUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
 * Created by Administrator on 2018/6/22 0022.
 */
@Service
public class RukuServiceImpl implements RukuService {

    @Autowired
    private RukuMapper rukuMapper;
    @Autowired
    private RukusonMapper rukusonMapper;
    @Autowired
    private ProductionDetailsMapper productionDetailsMapper;
    @Autowired
    private StoreMapper storeMapper;
    @Autowired
    private TailorMapper tailorMapper;
    @Autowired
    private TuihuoMapper tuihuoMapper;
    @Autowired
    private FinanceService financeService;


    @Override
    public List<Ruku> findRukuList(Ruku ruku, PageBean pageBean) {
        Map<String, Object> map = new HashMap<>();
        map.put("jgId", ruku.getJgId());
        if (StringUtils.isNotBlank(ruku.getRukudanhao())) {
            map.put("rukudanhao", ruku.getRukudanhao());
        }
        if (ruku.getRukuleixing() != null && -1 != ruku.getRukuleixing()) {
            map.put("rukuleixing", ruku.getRukuleixing());
        }
        if (StringUtils.isNotBlank(ruku.getStartTime())) {
            map.put("startTime", ruku.getStartTime());
        }
        if (StringUtils.isNotBlank(ruku.getEndTime())) {
            map.put("endtTime", ruku.getEndTime() + " 23:59:59");
        }
        if (ruku.getState() != null) {
            map.put("state", ruku.getState());
        } else {
            map.put("state", -1);
        }
        if (ruku.getState2() != null) {
            map.put("state2", ruku.getState2());
        } else {
            map.put("state2", -1);
        }
        if (ruku.getState3() != null) {
            map.put("state3", ruku.getState3());
        } else {
            map.put("state3", -1);
        }
        map.put("fenlei", ruku.getFenlei());
        map.put("start", pageBean.getStart());
        map.put("rows", pageBean.getRows());
        pageBean.setTotal(rukuMapper.findRukuListCount(map));
        return rukuMapper.findRukuList(map);
    }

    @Override
    public List<Rukuson> findRukuListSonById(Rukuson rukuson, Integer fenlei) {
        Map<String, Object> map = new HashMap<>();
        map.put("id", rukuson.getId());
        map.put("fenlei", fenlei);
        return rukusonMapper.findListByRukuId(map);
    }

    @Override
    public int commitRukudan(Ruku ruku) {
        //入库提交状态为1
        ruku.setState(1);
        int code = rukuMapper.commitRukudan(ruku);
        if (code <= 0) {
            throw new MyException("更新入库单失败，请检查数据重新尝试");
        }
        return code;
    }

    @Override
    public List<MyEntity> findTailorRuku(String id) {
        List<MyEntity> tailors = rukuMapper.findTailorRuku(id);
        if (tailors.size() > 0) {
            Map<String, Object> map = new HashMap<>();
            map.put("tailorId", "'" + id + "'");
            map.put("fenlei", 2);
            map.put("newDan", 0);
            List<Tailor> list = tailorMapper.findRukushuByTailorId(map);
            if (list.size() > 0) {
                StringBuffer danjuId = new StringBuffer();
                for (int j = 0; j < list.size(); j++) {
                    if (j == list.size() - 1) {
                        danjuId.append("'" + list.get(j).getDanjuId() + "'");
                    } else {
                        danjuId.append("'" + list.get(j).getDanjuId() + "',");
                    }
                }
                map.put("danjuId", danjuId);
                //查询入库退货数量
                List<Ruku> tuihuo = rukuMapper.findTaiorTui(map);
                if (tuihuo.size() != 0) {
                    for (int j = 0; j < list.size(); j++) {
                        for (int i = 0; i < tuihuo.size(); i++) {
                            if (tuihuo.get(i).getProduct().equals(list.get(j).getProduct()) && tuihuo.get(i).getColor().equals(list.get(j).getColor())
                                    && tuihuo.get(i).getSize().equals(list.get(j).getSize())) {
                                list.get(j).setYiruku(list.get(j).getYiruku() - Math.abs(tuihuo.get(i).getZongshuliang()));
                                break;
                            }
                        }
                    }
                }
                for (int j = 0; j < list.size(); j++) {
                    for (int i = 0; i < tailors.size(); i++) {
                        if (tailors.get(i).getProduct().equals(list.get(j).getProduct()) && tailors.get(i).getColor().equals(list.get(j).getColor())
                                && tailors.get(i).getSize().equals(list.get(j).getSize())) {
                            //裁剪数量-已入库数量=剩下来的数量
                            tailors.get(i).setShuliang(tailors.get(i).getShuliang() - list.get(j).getYiruku());
                            break;
                        }
                    }
                }
            }
        }
        return tailors;
    }

    @Override
    @Transactional
    public int saveRuku(String r, Ruku rukus) {
        String mes = "";
        if (StringUtils.isNotBlank(rukus.getId())) {//修改
            mes = "修改";
            //更新入库单
            int codes = rukuMapper.updateRuku(rukus);
            if (codes <= 0) {
                throw new MyException(mes + "入库单失败，请检查数据重新尝试");
            }
            //删除之前的数据 当入库类型为0的时候删除关系表数据 并且机构id为1
            if (rukus.getRukuleixing() == 0 && "1".equals(rukus.getJgId())) {
                int c = rukuMapper.delTailorRuku(rukus);
                if (c <= 0) {
                    throw new MyException(mes + "入库单失败，请检查数据重新尝试");
                }
            }
            //删除子表信息
            int cs = rukusonMapper.delRukuson(rukus);
            if (cs <= 0) {
                throw new MyException(mes + "入库单失败，请检查数据重试");
            }

        } else {//新增
            mes = "新增";
            //新增入库单
            rukus.setId(UUIDUtil.getUUID());
            int code = rukuMapper.insertRuku(rukus);
            if (code <= 0) {
                throw new MyException(mes + "入库单失败");
            }
        }
        JSONArray obj = JSONArray.parseArray(r);// 解析String 成JSONARRy
        List<Rukuson> list = new ArrayList<>();
        Set<String> set = new HashSet<>();
        for (int i = 0; i < obj.size(); i++) {
            JSONObject jo = (JSONObject) obj.get(i);
            Rukuson rukuson = new Rukuson();
            rukuson.setShuliang(Integer.parseInt(jo.get("shuliang").toString()));
            rukuson.setDanjia(Double.parseDouble(jo.get("danjia").toString()));
            //裁剪id
            set.add(jo.get("id").toString());
            //入库id放进去
            rukuson.setRukuId(rukus.getId());
            rukuson.setId(UUIDUtil.getUUID());
            //根据款号id 颜色 尺码查询cpzbid
            ProductionDetails productionDetails = new ProductionDetails();
            productionDetails.setSize(jo.get("size").toString());
            productionDetails.setColor(jo.get("color").toString());
            productionDetails.setProductionId(jo.get("productionId").toString());
            String productionDetailsId = productionDetailsMapper.findIdBy(productionDetails);
            if (productionDetailsId != null && !"".equals(productionDetailsId)) {
                rukuson.setProductionDetailsId(productionDetailsId);
                //把类放到集合里面
                list.add(rukuson);
            } else {
                throw new MyException("数据错误，请刷新重新尝试");
            }
        }
        //批量插入子表
        int cod = rukusonMapper.insertRukusonSome(list);
        if (cod <= 0) {
            throw new MyException(mes + "入库单失败");
        }
        //当入库类型为1的时候不需要新增关系表
        if (rukus.getRukuleixing() == 0 && "1".equals(rukus.getJgId())) {
            List<TailorRuku> TailorRukus = new ArrayList<>();
            //批量插入关系表
            for (String tailorId : set) {
                TailorRuku tailorRuku = new TailorRuku();
                tailorRuku.setId(UUIDUtil.getUUID());
                //放入库id
                tailorRuku.setRukuId(rukus.getId());
                //放裁剪id
                tailorRuku.setTailorId(tailorId);
                TailorRukus.add(tailorRuku);
            }
            int co = rukuMapper.insertTailorRuku(TailorRukus);
            if (co <= 0) {
                throw new MyException(mes + "入库单失败");
            }
        }
        return 1;
    }

    @Override
    @Transactional
    public int addRuku(Ruku ruku) {
        //更新裁剪单状态为1
        List<String> list = tailorMapper.findTailorIdByRukuId(ruku.getId());
        for (int i = 0; i < list.size(); i++) {
            Tailor tailor = new Tailor();
            tailor.setId(list.get(i));
            tailor.setState(1);
            int code = tailorMapper.updateState(tailor);
        }

        //更新入库单状态为2
        int code = rukuMapper.ruku(ruku);
        if (code <= 0) {
            throw new MyException("入库失败，请检查数据重新尝试");
        }
        //根据入库单id查询所有子表信息
        List<Rukuson> rukusons = rukusonMapper.findRukuSonListById(ruku);
        //入库类型等于3的时候
        if (rukusons.size() != 0 && rukusons.get(0).getLeixing() == 3) {
            List<Store> stores = new ArrayList<>();
            //根据入库子表的id去更新库存表里的数量
            for (int i = 0; i < rukusons.size(); i++) {
                Store store = new Store();
                store.setShuliang(rukusons.get(i).getShuliang());
                store.setJgId(ruku.getJgId());
                store.setLeixing(0);
                store.setProductionDetailsId(rukusons.get(i).getProductionDetailsId());
                stores.add(store);

                Store store2 = new Store();
                store2.setLeixing(1);
                store2.setShuliang(rukusons.get(i).getShuliang() * -1);
                store2.setJgId(ruku.getJgId());
                store2.setProductionDetailsId(rukusons.get(i).getProductionDetailsId());
                stores.add(store2);
            }
            int cos = storeMapper.updateShuliang(stores);
            if (cos <= 0) {
                throw new RuntimeException("入库失败，请检查数据重新尝试");
            }
        } else {
            //根据得到的信息看库存是否已经存在该商品
            Map<String, Object> map = new HashMap<>();
            map.put("jgId", ruku.getJgId());
            int storesum = 0;
            List<String> productionDetailsIdInsert = new ArrayList<>();
            List<String> productionDetailsIdUpdate = new ArrayList<>();
            for (int i = 0; i < rukusons.size(); i++) {
                map.put("productionDetailsId", rukusons.get(i).getProductionDetailsId());
                //查询store表是否存在该子表信息
                storesum = storeMapper.findStoreByJgIdAndProductionDetailsId(map);
                if (storesum == 0) {
                    //里面没有的产品子表id
                    productionDetailsIdInsert.add(rukusons.get(i).getProductionDetailsId());
                } else {
                    productionDetailsIdUpdate.add(rukusons.get(i).getProductionDetailsId());
                }
            }
            //批量新增集合
            List<Store> insertSome = new ArrayList<>();
            //更新字段
            List<Store> updateSome = new ArrayList<>();
            for (int i = 0; i < rukusons.size(); i++) {
                for (int j = 0; j < productionDetailsIdInsert.size(); j++) {
                    //判断是否相等 相等就新增insertSome
                    if (rukusons.get(i).getProductionDetailsId().equals(productionDetailsIdInsert.get(j))) {
                        Store store = new Store();
                        store.setId(UUIDUtil.getUUID());
                        store.setProductionDetailsId(rukusons.get(i).getProductionDetailsId());
                        store.setJgId(ruku.getJgId());
                        //0是正常库存1是次品厂
                        store.setLeixing(0);
                        store.setShuliang(rukusons.get(i).getShuliang());
                        insertSome.add(store);
                        break;
                    }
                }
                for (int j = 0; j < productionDetailsIdUpdate.size(); j++) {
                    if (rukusons.get(i).getProductionDetailsId().equals(productionDetailsIdUpdate.get(j))) {
                        Store store = new Store();
                        store.setShuliang(rukusons.get(i).getShuliang());
                        store.setJgId(ruku.getJgId());
                        if (rukusons.get(i).getLeixing() == 3) {
                            store.setLeixing(1);
                        } else {
                            store.setLeixing(0);
                        }
                        store.setProductionDetailsId(rukusons.get(i).getProductionDetailsId());
                        updateSome.add(store);
                        break;
                    }
                }
            }
            //两个都为空就回滚
            if (insertSome.size() == 0 && updateSome.size() == 0) {
                throw new MyException("入库失败，请检查数据重新尝试");
            }
            //新增库存
            if (insertSome.size() != 0) {
                int addCode = storeMapper.insertStoreSome(insertSome);
                if (addCode <= 0) {
                    throw new MyException("入库失败，请检查数据重新尝试");
                }
                //jgid为1的就新增次品厂库
                if ("1".equals(ruku.getJgId())) {
                    addCode = storeMapper.insertStoreCipin(insertSome);
                    if (addCode <= 0) {
                        throw new MyException("入库失败，请检查数据重新尝试");
                    }
                }
            }
            //更新库存
            if (updateSome.size() != 0) {
                int updateCode = storeMapper.updateShuliang(updateSome);
                if (updateCode <= 0) {
                    throw new MyException("入库失败，请检查数据重新尝试");
                }
            }
            // 计算财务
            Ruku ru = rukusonMapper.findRukuById(ruku.getId());
            FinanceRecord recordRu = new FinanceRecord();
            recordRu.setAmount(Math.abs(ru.getZongjia()) * -1);
            recordRu.setGsjg(ru.getJgId());
            recordRu.setWldw(ru.getGongyingshangid());
            recordRu.setYddid(ru.getRukudanhao());
            recordRu.setHl("" + (1));
            recordRu.setTime(new Date());
            recordRu.setWldwType(0);
            //0是自产1是采购入库2是分销入库3次品
            if (ru.getRukuleixing() == 0) {
                recordRu.setFslx("自产入库");
            } else if (ru.getRukuleixing() == 1) {
                recordRu.setFslx("采购入库");
            } else if (ru.getRukuleixing() == 2) {
                recordRu.setFslx("分销入库");
            }
            financeService.addFinanceRecord(recordRu);
        }
        return code;
    }

    @Override
    @Transactional
    public int tuiHuo(Ruku ruku) {
        //更改退货单状态为2
        int code = rukuMapper.ruku(ruku);
        if (code <= 0) {
            throw new MyException("入库失败，请检查数据重新尝试");
        }
        //根据入库单id查询所有子表信息
        List<Rukuson> rukusons = rukusonMapper.findRukuSonListById(ruku);
        List<Store> stores = new ArrayList<>();
        //减少库存
        for (int i = 0; i < rukusons.size(); i++) {
            Store store = new Store();
            store.setProductionDetailsId(rukusons.get(i).getProductionDetailsId());
            store.setJgId(ruku.getJgId());
            store.setLeixing(0);
            store.setShuliang(rukusons.get(i).getShuliang());
            stores.add(store);
        }
        //批量更新库存
        int co = storeMapper.updateShuliang(stores);
        if (co <= 0) {
            throw new MyException("入库失败，请检查数据重新尝试");
        }
        // 财务
        Ruku ru = rukusonMapper.findRukuById(ruku.getId());
        FinanceRecord recordRu = new FinanceRecord();
        recordRu.setAmount(Math.abs(ru.getZongjia()));
        recordRu.setGsjg(ru.getJgId());
        recordRu.setWldw(ru.getGongyingshangid());
        recordRu.setYddid(ru.getRukudanhao());
        recordRu.setHl("" + (-1));
        recordRu.setTime(new Date());
        recordRu.setWldwType(0);
        //0是自产1是采购入库2是分销入库3次品
        if (ru.getRukuleixing() == 0) {
            recordRu.setFslx("自产退货");
        } else if (ru.getRukuleixing() == 1) {
            recordRu.setFslx("采购退货");
        } else if (ru.getRukuleixing() == 2) {
            recordRu.setFslx("分销退货");
        }
        financeService.addFinanceRecord(recordRu);
        return co;
    }

    @Override
    public int restRuku(Ruku ruku) {
        //更新单据信息到草稿状态 0
        int code = rukuMapper.restRuku(ruku);
        if (code <= 0) {
            throw new MyException("入库失败，请检查数据重新尝试");
        }
        //根据id查询出该单子信息

        //更新库存

        //跟新财务

        return 0;
    }


    @Override
    public int delRuku(Ruku ruku) {
        int code = rukuMapper.delRuku(ruku);
        if (code <= 0) {
            throw new MyException("删除入库单失败，请检查数据重新尝试");
        }
        return code;
    }

    @Override
    public int bohui(Ruku ruku) {
        int code = rukuMapper.bohui(ruku);
        if (code <= 0) {
            throw new MyException("驳回入库单失败，请检查数据重新尝试");
        }
        return code;
    }

    @Override
    public List<Rukuson> findRukuByRukuId(Ruku ruku) {
        List<Rukuson> list = rukuMapper.findRukuByRukuId(ruku);
        if (list.size() != 0) {
            //入库类型为1就不需要查裁剪单 0为自产1为进货 机构id为1的才需要查询裁剪单 入库类型为3是次品退货
            if (list.get(0).getLeixing() == 3 || list.get(0).getLeixing() == 1 || !"1".equals(ruku.getJgId())) {
                return list;
            }
        }

        Map<String, Object> map = new HashMap<>();
        map.put("fenlei", 2);
        map.put("id", ruku.getId());
        //根据裁剪id查询裁剪数据
        List<Tailor> tailors = tailorMapper.findTailorList(map);
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < tailors.size(); i++) {
            if (tailors.size() - 1 == i) {
                buffer.append("'" + tailors.get(i).getId() + "'");
                break;
            }
            buffer.append("'" + tailors.get(i).getId() + "',");
        }
        map.put("tailorId", buffer.toString());
        map.put("newDan", 0);
        //根据裁剪单查询入库单入库数量
        List<Tailor> rukus = tailorMapper.findRukushuByTailorId(map);
        for (int i = 0; i < tailors.size(); i++) {
            for (int j = 0; j < rukus.size(); j++) {
                if (tailors.get(i).getProduct().equals(rukus.get(j).getProduct())
                        && tailors.get(i).getColor().equals(rukus.get(j).getColor())
                        && tailors.get(i).getSize().equals(rukus.get(j).getSize())
                        ) {
                    tailors.get(i).setCaijianshuliang(tailors.get(i).getCaijianshuliang() - rukus.get(j).getYiruku());
                    break;
                }
            }
        }
        //拿到可入库数量
        for (int i = 0; i < list.size(); i++) {
            for (int j = 0; j < tailors.size(); j++) {
                if (list.get(i).getProduct().equals(tailors.get(j).getProduct())
                        && list.get(i).getColor().equals(tailors.get(j).getColor())
                        && list.get(i).getSize().equals(tailors.get(j).getSize())
                        ) {
                    list.get(i).setKerushuliang(tailors.get(j).getCaijianshuliang() + list.get(i).getShuliang());
                    list.get(i).setTiepai(tailors.get(j).getTiepai());
                    list.get(i).setId(tailors.get(j).getId());
                }
            }
        }
        return list;
    }

    @Override
    public List<Ruku> findRukuDan(Ruku ruku, String q) {
        Map<String, Object> map = new HashMap();
        if (StringUtils.isNotBlank(q)) {
            map.put("product", q);
        }
        if (StringUtils.isNotBlank(ruku.getId())) {
            map.put("id", ruku.getId());
        }
        map.put("jgId", ruku.getJgId());
        map.put("rukuleixing", ruku.getRukuleixing());
        List<Ruku> rukus = rukuMapper.findRukuDan(map);
        //过滤掉无用数据
        for (int i = 0; i < rukus.size(); i++) {
            if (rukus.get(i).getZongshuliang() == 0) {
                rukus.remove(i);
                --i;
            }
        }
        return rukus;
    }

    @Override
    public List<RukuTuiCombobox> findProductByRukuId(Ruku ruku) {
        List<RukuTuiCombobox> list = rukuMapper.findProductByRukuId(ruku);
        return list;
    }

    @Override
    public List<RukuTuiCombobox> findDetails(Ruku ruku) {
        //查询该单的出库订单
        List<RukuTuiCombobox> list = rukuMapper.findDetails(ruku);

        List<RukuTuiCombobox> yitui = rukuMapper.findDetailsYitui(ruku);
        for (int i = 0; i < list.size(); i++) {
            for (int j = 0; j < yitui.size(); j++) {
                if (list.get(i).getProductionDetailsId().equals(yitui.get(j).getProductionDetailsId())) {
                    list.get(i).setShuliang(list.get(i).getShuliang() + yitui.get(j).getShuliang());
                }
            }
        }
        return list;
    }

    @Override
    @Transactional
    public int saveTui(String ruku, Ruku rukus) {
        if (StringUtils.isNotBlank(rukus.getId())) {
            //修改
            //更新主表
            int codes = rukuMapper.updateRuku(rukus);
            if (codes <= 0) {
                throw new MyException("修改失败，请检查数据重新尝试");
            }
            //根据入库id删除子表
            rukusonMapper.delRukuson(rukus);
            //删除关系表
            tuihuoMapper.delTuihuo(rukus);
        } else {
            //新增
            //新增入库单
            rukus.setId(UUIDUtil.getUUID());
            int code = rukuMapper.insertRuku(rukus);
            if (code <= 0) {
                throw new MyException("新增入库单失败");
            }
        }
        //新增关系表
        Tuihuo tuihuo = new Tuihuo();
        tuihuo.setId(UUIDUtil.getUUID());
        //被退货的id
        tuihuo.setDanjuId(rukus.getRukuId());
        //退货的id
        tuihuo.setTuihuoId(rukus.getId());
        tuihuoMapper.insert(tuihuo);
        JSONArray obj = JSONArray.parseArray(ruku);// 解析String 成JSONARRy
        List<Rukuson> list = new ArrayList<>();
        for (int i = 0; i < obj.size(); i++) {
            JSONObject jo = (JSONObject) obj.get(i);
            Rukuson rukuson = new Rukuson();
            //退货是-的
            rukuson.setShuliang(Integer.parseInt(jo.get("shuliang").toString()) * -1);
            rukuson.setDanjia(Double.parseDouble(jo.get("danjia").toString()));
            //入库id放进去
            rukuson.setRukuId(rukus.getId());
            rukuson.setId(UUIDUtil.getUUID());
            //根据款号id 颜色 尺码查询cpzbid
            ProductionDetails productionDetails = new ProductionDetails();
            productionDetails.setSize(jo.get("size").toString());
            productionDetails.setColor(jo.get("color").toString());
            productionDetails.setProductionId(jo.get("productionId").toString());
            String productionDetailsId = productionDetailsMapper.findIdBy(productionDetails);
            if (productionDetailsId != null && !"".equals(productionDetailsId)) {
                rukuson.setProductionDetailsId(productionDetailsId);
                //把类放到集合里面
                list.add(rukuson);
            } else {
                throw new MyException("数据错误，请刷新重新尝试");
            }
        }
        //批量插入子表
        int cod = rukusonMapper.insertRukusonSome(list);
        if (cod <= 0) {
            throw new MyException("新增入库单失败");
        }
        return cod;
    }

    @Override
    public List<Rukuson> findRukuTuiByRukuId(Ruku ruku) {
        //查询单据id
        String rukuId = rukuMapper.findDanjuId(ruku);
        ruku.setRukuId(rukuId);
        List<Rukuson> list = rukuMapper.findRukuByRukuId(ruku);
        //根据rukuid查询关联表被退货订单的id
        List<RukuTuiCombobox> tuihuo = rukuMapper.findTuihuoByTuihuoId(ruku);
        //查询一共可退货的数量
        List<RukuTuiCombobox> tuihuos = rukuMapper.findTuihuo(ruku);
        for (int i = 0; i < tuihuos.size(); i++) {
            for (int j = 0; j < tuihuo.size(); j++) {
                if (tuihuos.get(i).getProductionDetailsId().equals(tuihuo.get(j).getProductionDetailsId())) {
                    tuihuos.get(i).setShuliang(tuihuos.get(i).getShuliang() + tuihuo.get(j).getShuliang());
                }
            }
        }
        for (int i = 0; i < list.size(); i++) {
            for (int j = 0; j < tuihuos.size(); j++) {
                if (list.get(i).getProductionDetailsId().equals(tuihuos.get(j).getProductionDetailsId())) {
                    list.get(i).setKerushuliang(Math.abs(tuihuos.get(j).getShuliang()));
                }
            }
            list.get(i).setShuliang(Math.abs(list.get(i).getShuliang()));
            list.get(i).setRukuId(rukuId);
        }
        return list;
    }

}
